import * as Koa from 'koa'
import * as userService from '../services/user.service'
import { IUser } from '../types'

export default async function (ctx: Koa.Context, next: Koa.Next) {
  const token = ctx.cookies.get('token')
  let userInfo: IUser
  try {
    userInfo = await userService.userInfo(token)
  } catch (error) {}
  ctx.state.userInfo = userInfo
  await next()
}
